package com.fu.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 付大大
 * @description
 * @create 2021-01-31 14:19
 */
public class Test {
    public static void main(String[] args) {
        Student student = new Student();
        StudentInterface proxyStu = (StudentInterface) Proxy.newProxyInstance(student.getClass().getClassLoader(), new Class[]{StudentInterface.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if (method.getName().equals("study")) {
                    System.out.println("来黑马学习");
                    return null;
                } else {
                    return method.invoke(student, args);
                }
            }
        });


        proxyStu.eat("米饭");
        proxyStu.study();
    }
}
